Skip to content

Conversation

@ashleysommer
Copy link

@ashleysommer ashleysommer commented Aug 22, 2024

The ASGIMiddleware class has a state (Dict) property.
State can be written to if the ASGI Lifespan startup handler writes to it, but it is never used for anything after that.

The ASGI Spec states that contents of the lifespan startup's state dict is stored by the ASGI server, and the state is added to any subsequent ASGI Requests.
https://asgi.readthedocs.io/en/latest/specs/lifespan.html

Applications often want to persist data from the lifespan cycle to request/response handling. ... The server will ensure that a shallow copy of the namespace is passed into each subsequent request/response call into the application.

This PR implements that final missing link, adds a shallow copy of the state dict to every subsequent ASGI Request, as specified in the ASGI spec.

Fixes Azure/azure-functions-python-worker#1566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ASGIFunctionApp - scope.state from lifespan startup is not delivered in subsequent request.state

1 participant